<template>
  <div class="page-scan-mana">
    <el-form :inline="true" :model="dataQueryForm" ref="dataQueryForm">
      <div class="pc-page-header">
        <el-form-item prop="id">
          <el-input v-model="dataQueryForm.projectNo" clearable class="pc-input3-col5" placeholder="输入项目编号"></el-input>
        </el-form-item>
        <el-form-item prop="id">
          <el-input v-model="dataQueryForm.userCompanyName" clearable class="pc-input3-col5" placeholder="输入企业名称"></el-input>
        </el-form-item>
        <el-form-item prop="id">
          <el-select v-model="dataQueryForm.tradeType" multiple  collapse-tags class="pc-input3-col6" placeholder="选择业务类型" value="">
            <el-option v-for="item in tradeTypeOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="id">
          <el-select v-model="dataQueryForm.status" multiple  collapse-tags class="pc-input3-col5" placeholder="选择状态" value="">
            <el-option v-for="item in statusOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="queryDataFn">搜索</el-button>
          <el-button type="primary" @click="refresh('dataQueryForm')">刷新</el-button>
        </el-form-item>
      </div>
    </el-form>

    <!--列表数据-->
    <egrid border class="page-list"
           :data="tableData"
           :columns="columns"
           :columns-schema="columnsSchema"
           :columns-props="columnsProps">
    </egrid>

    <!--分页组件-->
    <div class="pc-pagination-panel">
      <pc-pagination ref="pcPagination" :url="pageUrl.queryDataList" :queryData="dataQueryForm"
                     @on-query="queryCallBackFn">
      </pc-pagination>
    </div>

    <!--项目详情页面-->
    <pc-dialog :is-show="isShowDetailDialog" title='项目详情' @on-close="isShowDetailDialog = false" width="1400">
      <div>
        <detail :projectInfo="projectInfo">
        </detail>
      </div>
    </pc-dialog>

    <!--设置违约页面-->
    <pc-dialog-center :is-show="isShowEditViolateDialog" title='设置违约方' @on-close="isShowEditViolateDialog = false" width="320" height="200">
      <div>
        <edit-violate :projectInfo="projectInfo" @sure="afterEditViolate()">
        </edit-violate>
      </div>
    </pc-dialog-center>

  </div>
</template>

<script type="text/ecmascript-6">
  import PcPagination from 'components/form/pagination';
  import PcButton from 'components/form/button';
  import PcDialog from 'components/dialog';
  import PcDialogCenter from 'components/dialog/center.vue';
  import EgridCellView from 'components/wms/comm/EgridCellView.vue';
  import {enums} from '../../../../utils/settings';
  import Detail from './detail.vue';
  import EditViolate from './editViolate.vue';
  let that;

  // 项目编码链接详情
  var projectNoLink = {
    template: ` <el-button class="base-project-no" @click="viewdetail(row)" type="text" size="small">{{this.row.projectNo}}</el-button>`,
    props: ['row'],
    methods: {
      viewdetail(val) {
        this.$emit('view-detail', val);
      }
    }
  };

  // 操作按钮
  var Btn = {
    template: `<div style="display:flex; width: 100%;flex-wrap: wrap">
        <el-button v-if="showEditViolateBtn" type="primary" plain @click="gotoEditViolate(row)">设置违约</el-button>
      </div>`,
    props: ['row'],
    computed: {
      // 是否显示设置违约按钮
      showEditViolateBtn() {
        return this.row.status === enums.SK_PROJECT_STATUS.CXZ || this.row.status === enums.SK_PROJECT_STATUS.YYQ || this.row.status === enums.SK_PROJECT_STATUS.YWC;
      }
    },
    methods: {
      // 跳转设置违约
      gotoEditViolate (val) {
        this.$emit('edit-violate', val);
      }
    }
  };

  export default {
    data() {
      return {
        projectInfo: null,
        isShowDetailDialog: false,
        isShowEditViolateDialog: false,
        dataQueryForm: {
          statusRange: [4, 5, 6, 7],
          projectNo: null,
          tradeType: [],
          status: [],
          userCompanyName: null,
          ownerName: null,
          storageName: null
        },
        tableData: [],
        columns: [
          {
            label: '项目编号',
            // prop: 'projectNo'
            component: projectNoLink,
            listeners: {
              'view-detail' (val) {
                that.viewDetailFn(val);
              }
            }
          },
          {
            label: '执行日期',
            prop: 'performDate'
          },
          {
            label: '企业名称',
            prop: 'userCompanyName'
          },
          {
            label: '业务类型',
            prop: 'tradeTypeDisplay'
          },
          {
            label: '状态',
            prop: 'statusDisplay'
          },
          {
            label: '资产总额(元)',
            prop: 'totalAmount'
          },
          {
            label: '执行折率',
            prop: 'discountRateDeclareDisplay'
          },
          {
            label: '折后总价(元)',
            prop: 'totalDiscountedAmountDeclare'
          },
          {
            label: '待赎资产(元)',
            prop: 'leftDiscountedAmount'
          },
          {
            label: '融资天数',
            prop: 'tradeDays'
          },
          {
            label: '剩余天数',
            prop: 'leftDays'
          },
          {
            label: '风险系数',
            prop: 'riskCoefficient'
          },
          {
            label: '违约方',
            prop: 'violatorDisplay'
          },
          {
            label: '操作',
            minWidth: 100,
            fixed: 'right',
            component: Btn, // 'el-button'
            listeners: {
              'edit-violate' (data) {
                that.viewEditViolateFn(data);
              }
            },
            propsHandler: function ({ row, col, column }) {
              return {row, col, column};
            }
          }
        ],
        columnsSchema: {
          '项目编号': {minWidth: 100},
          '执行日期': {minWidth: 85},
          '业务类型': {minWidth: 80},
          '状态': {minWidth: 70},
          '资产总额(元)': {minWidth: 120},
          '执行折率': {minWidth: 80},
          '折后总价(元)': {minWidth: 120},
          '待赎资产(元)': {minWidth: 120},
          '融资天数': {minWidth: 80},
          '剩余天数': {minWidth: 80},
          '风险系数': {minWidth: 80},
          '违约方': {minWidth: 80}
        },
        selecetedRows: [],
        // columnsProps 用于定义所有 columns 公共的属性，
        // 这里属性可以参考这里： http://element.eleme.io/#/zh-CN/component/table#table-column-attributes
        columnsProps: {
          height: 40,
          minWidth: 150,
          showOverflowTooltip: true,
          component: EgridCellView
        },
        statusOption: [
          {
            value: 1,
            label: '待审核'
          }, {
            value: 2,
            label: '不通过'
          }, {
            value: 3,
            label: '待定中'
          }
        ],
        tradeTypeOption: [
          {
            value: 1,
            label: '现货质押'
          }, {
            value: 2,
            label: '贸易融资'
          }, {
            value: 3,
            label: '商贸模式'
          }
        ],
        // columnsHandler 可用于在现有的 columns 进行操作，对 columns 进行增删改，这里新增了操作列
        pageUrl: {
          queryDataList: '/malisk/server/project/queryProjectList'
        }
      };
    },
    components: {
      PcPagination, PcButton, PcDialog, Detail, PcDialogCenter, EditViolate
    },
    created() {
      that = this;
    },

    methods: {
      // 表头样式
      getHeaderStyle({row, column, rowIndex, columnIndex}) {
        if (rowIndex === 0) {
          return 'background: #f5f5f5; height: 50px';
        } else {
          return '';
        }
      },
      getRowClass({row, column, rowIndex, columnIndex}) {
        if (rowIndex === 0) {
          return 'background:rgb(245, 245, 245);';
        } else {
          return '';
        }
      },
      viewDetailFn (scopeRow) {
        this.projectInfo = scopeRow;
        this.isShowDetailDialog = true;
      },
      viewEditViolateFn (scopeRow) {
        this.projectInfo = scopeRow;
        this.dialogTitle = '设置违约';
        this.isShowEditViolateDialog = true;
      },
      openMessage() {
        this.$notify.info({
          title: '自定义位置',
          message: '右下角弹出的消息',
          position: 'bottom-right'
        });
      },
      afterEditViolate() {
        this.isShowEditViolateDialog = false;
        this.$refs.pcPagination.queryListWithPageFn(false);
      },
      queryCallBackFn(res) {
        this.tableData = res.result.list;
      },
      queryDataFn() {
        this.$refs.pcPagination.queryListWithPageFn(true);
      },
      refresh(formName) {
        this.$refs[formName].resetFields();
        this.dataQueryForm.statusRange = [4, 5, 6, 7];
        this.dataQueryForm.projectNo = null;
        this.dataQueryForm.tradeType = [];
        this.dataQueryForm.status = [];
        this.dataQueryForm.userCompanyName = null;
        this.dataQueryForm.ownerName = null;
        this.dataQueryForm.storageName = null;
        this.queryDataFn();
      }
    }
  };
</script>
<style>
  .base-project-no {
    padding: 5px 0px !important;
  }
</style>
